﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using EchoLink;

namespace EchoLinkMonitor
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }

        private void Main_Load(object sender, EventArgs e)
        {
            try
            {
                // Get the EchoLink session object
                EchoLinkSession elSession = new EchoLinkSession();

                // Grab the basic setup information object
                SetupConfig elSetup = elSession.SystemConfig;

                // Grab the advances (sysop) information object
                SysopConfig elSysopSetup = elSession.SysopConfig;

                // Collect configuration info for display
                StringBuilder infoBuilder = new StringBuilder();
                // User info first
                infoBuilder.Append(string.Format("Operator Info: {0} - {1} ({2})\r\n", elSetup.Name, elSetup.Callsign, elSetup.Email));
                // Location info
                infoBuilder.Append(string.Format("Station Info: \r\n\tLocation: {0}\r\n\tConnections: {1:d}/{2:d}\r\n\t", elSetup.Location, elSession.NumPeers, elSetup.MaxPeers));
                // Current operating mode
                infoBuilder.Append(string.Format("Mode: {0}\r\n\t", elSetup.Mode == elOperatingMode.opModeSingleUser ? "Single user" : "SysOp"));
                // Path to the station information file
                infoBuilder.Append(string.Format("Information File: {0}\r\n\t", elSetup.StationInformationFile));
                // TODO: Contents of the station information file
                // Favorite contacts list
                CallsignList favList = (CallsignList)elSetup.FavoritesList;
                infoBuilder.Append(string.Format("Favorites List:", favList.GetType()));

                for(int idx = 0; idx < favList.Count; idx++)
                {
                    infoBuilder.Append("\r\n\t\t" + favList[idx]);
                }

                infoBuilder.Append("\r\n");

                // Update UI
                output.Text = infoBuilder.ToString();
            }
            // Catch any booboos
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString());
            }

            return;
        }
    }
}
